class Solution(object):
    def minWindow(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        lookuptabel = {}
        searchtabel = {}
        for item in t:
            if item in lookuptabel:
                lookuptabel[item] += 1
            else:
                lookuptabel[item] = 1
                searchtabel[item] = 0

        left_index = 0
        len_item = len(lookuptabel)
        now_item = 0
        right_index = 0
        length = len(s)
        min_value = -1
        min_i = -1
        min_j = -1
        while right_index < length:
            if s[right_index] in searchtabel:
                searchtabel[s[right_index]] += 1
                if searchtabel[s[right_index]] == lookuptabel[s[right_index]]:
                    now_item += 1
                if now_item == len_item:
                    while left_index <= right_index:
                        if s[left_index] not in searchtabel:
                            left_index += 1
                        else:
                            if searchtabel[s[left_index]] - 1 < lookuptabel[s[left_index]]:
                                break
                            else:
                                searchtabel[s[left_index]] = searchtabel[s[left_index]] - 1
                                left_index += 1
                    now_value = right_index - left_index + 1
                    if min_value < 0:
                        min_value = now_value
                        min_i = left_index
                        min_j = right_index
                    else:
                        if now_value < min_value:
                            min_value = now_value
                            min_i = left_index
                            min_j = right_index
                    if min_value == len(t):
                        break
                    searchtabel[s[left_index]] -= 1
                    left_index += 1
                    now_item -= 1
            right_index += 1

        if min_value > 0:
            return s[min_i: min_j + 1]
        else:
            return ''


data = Solution()
s = "ABCACED"
t = "CC"
print(data.minWindow(s, t))
